package br.unifor.mia.olio.xml;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;

@XmlRootElement(name="benchResults")
public class BenchResult {

	
	private DriverSummary driverSummary;
	
	
	@XmlElement(name="driverSummary")
	public DriverSummary getDriverSummary() {
		return driverSummary;
	}

	public void setDriverSummary(DriverSummary driverSummary) {
		this.driverSummary = driverSummary;
	}

	public static String loadUrl(String url) throws IOException {

		HttpClient httpclient = new DefaultHttpClient();
		HttpGet httpget = new HttpGet(url);

		// Create a response handler
		ResponseHandler<String> responseHandler = new BasicResponseHandler();
		String responseBody = httpclient.execute(httpget, responseHandler);

		return responseBody;
	}
	
	public static void main(String[] args) throws JAXBException, MalformedURLException {
		JAXBContext jc = JAXBContext.newInstance(BenchResult.class);
		Unmarshaller um = jc.createUnmarshaller();
		URL url = new URL("http://192.168.56.101:9980/output/OlioDriver.12U/summary.xml");
		BenchResult teste = (BenchResult) um.unmarshal(url);
		
		
		
		System.out.println("name "+teste.driverSummary.getResponseTimes());
		
		System.out.println("name "+teste.driverSummary.getDelayTimes());
		
		
	}
	 	
}
